<template>
	<view>
		<view class="detail_header_title">
			单号-{{Detail_code}}
			
		<!-- 	<image  src="../../../static/changeIcon.png" @tap="Switchstyles()" ></image> -->
		</view>
		<scroll-view scroll-x class="detail_body">
		
		<view class="Detail_table" v-show="Switchstyle==1" style="background-color: #FFFFFF;"> <!-- 表格形式 -->
						<scroll-view scroll-x style="width: 1650px;">
						<table border="1" class="Detail_table_list" >
						  <tr class="trtdpadd">
						    <th nowrap="nowrap">序号</th>
							<th nowrap="nowrap">商品名称</th>
							<th nowrap="nowrap">编号</th>
							<th nowrap="nowrap">规格</th>
							<th nowrap="nowrap">单位</th>
							<th nowrap="nowrap">仓库</th>
							<th nowrap="nowrap">批号</th>
					<!-- 		<th nowrap="nowrap">生产日期</th>
							<th nowrap="nowrap">到期日期</th> -->
							<th nowrap="nowrap">单价</th>
							<th nowrap="nowrap">折扣</th>
							<th nowrap="nowrap">金额</th>
							<th nowrap="nowrap">数量</th>
							<th nowrap="nowrap">备注</th>
						  </tr>
						  <tr v-for="(item,index) in Detail_info" :key="item.id" class="trtdpadd">
						    <td> {{index+1}}</td>
							<td>{{item.GoodsName}}</td>
							<td>{{item.GoodsCode}}</td>
							<td>{{item.Spec}}</td>
							<td>{{item.UnitName}}</td>
							<td>{{item.stockName}}</td>
							<td>{{item.BatchNo  || ""}}</td>
							<!-- <td>{{timesubstr(item.ProductionDate)}}</td>
							<td>{{timesubstr(item.validityDate)}}</td> -->
							<td>{{toFix(item.inPrice)}}</td>
							<td>{{item.Discount}}</td>
							<td>{{toFix(item.Amount)}}</td>
							<td>{{toFix(item.Qty)}}</td>
							<td>{{item.Remark}}</td>
						  </tr>
						
						</table>
						</scroll-view>
					</view>
					<!-- 列表形式 -->
					<scroll-view scroll-y style="overflow-y: scroll;height: 82%;padding-bottom: 60px;" v-show="Switchstyle==2">
						<!-- :class="['user_list',{'user_list_success':index == checklist}]" -->
					<view v-for="(item,index) in Detail_info" :class="['item_list',{'item_table':index == unfold}] "  :key="item.id">
						<p>商品名称：{{item.GoodsName}}</p>
						<p>编号：{{item.GoodsCode}} <span style="margin-left: 15px;">规格：{{item.Spec}}</span></p>
						<p>单位：{{item.UnitName}}<span style="margin-left: 15px;">仓库：{{item.stockName}}</span></p>
						<p>批号：{{item.BatchNo  || ""}}</p>
						<!-- <p>生产日期：{{timesubstr(item.ProductionDate)}} <span style="margin-left: 15px;">到期日期：{{timesubstr(item.validityDate)}}</span></p> -->
						<p>单价：{{toFix(item.inPrice)}} <span style="margin-left: 15px;">折扣：{{item.Discount}}</span></p>
						<p>金额：{{toFix(item.Amount)}}<span style="margin-left: 15px;">数量：{{toFix(item.Qty)}}</span></p>
						<p>备注：{{item.Remark}}</p>
						<div class="radius" @tap="unfolds(index)">
							<div class="d3" v-if="index != unfold"></div>
							<div class="d4" v-else></div>
						</div>
					</view>
		<!-- 			<div class="aaaa">
						<div class="d3"></div>
						
					</div>
					<div class="aaaa">
						<div class="d4"></div>
						
					</div> -->
					
					
						</scroll-view>
		</scroll-view>
		<view class="Detail_footer">
			<view class="Detail_sum">总行数:{{Detail_length}} 总数量:{{Detail_sum}} 总金额:{{Detail_money}}</view>
			<view class="btnall">
				<view class="btn_back" @tap="back">返回上页</view>
				<!-- <view class="btn_back" @tap="change">修改单据</view> -->
			</view>
			
		</view>
	</view>
</template>

<script>
	import * as ApiBb from '@/syApis/sygetOrder/apis.js';
	export default {
		data() {
			return {
				Detail_info:[],//商品明细数据
				Detail_length:0,//商品明细总行数
				Detail_sum:0,//商品明细总数量
				Detail_money:0,//商品明细总金额
				Detail_code:'',//商品明细单号
				Switchstyle:2, //明细风格切换
				unfold:-1,// 展开
		        BillType:"",//单据类型
				NowOrder:{}
			}
		},
		onLoad:function(options){
			this.Detail_code = options.BillNo; //明细单号
			let  detailid= options.id;
			this.BillType = options.BillType;
			console.log('新的页面打印')
			console.log(options)
		
								// 采购入库单明细
				this.selectDetail(detailid)//初始化查询明细
				this.getThisOrder(detailid)
			
		},
		methods: {
			//修改单据
			change(){
				let BillName = "盘点单"
				uni.navigateTo({
					url: "../../add-order-Inventory/add-order-Inventory?BillName=" +BillName +"&oldOrder="+JSON.stringify(this.NowOrder)+"&type=1"
				})
			},
			//获取当条数据
			getThisOrder(BillID){
				let data = {
					BillType:this.BillType,
					Filter:"BillID="+BillID
				}
				var that = this;
				ApiBb.SelectBillInventory(data,function(res){
						  if(res.state){
							   if(res.data.ErrorMsg=="获取登录信息失败"){
								   ApiBb.showTip("登录超时");
							   }else if(res.data.ErrorMsg!=""){
								   ApiBb.showTip(res.data.ErrorMsg);
							   }else if(res.data.TipsMsg == "OK" && res.data.ResultMsg == ""){
								   ApiBb.showTip("查无数据");
							   }else{
								   that.NowOrder = res.data.ResultMsg[0];
							   }
						  }else{
							  ApiBb.showTip("服务器错误!");
						  }
					});
				
			},
			// 查看明细
			selectDetail:function(e){
					var that = this;
					let ClientID = uni.getStorageSync("UserCode");
					let CreateName = uni.getStorageSync("UserName");
					let Detailid =  e;
					let data = {
						BillType:this.BillType,
						Database:'FastApp',
						BillID:Detailid,
					};
					ApiBb.SelectBillInventoryDetail(data,function(res){
						  if(res.state){
							  console.log(res)
							   if(res.data.ErrorMsg=="获取登录信息失败"){
								   ApiBb.showTip("登录超时");
							   }else if(res.data.ErrorMsg!=""){
								   ApiBb.showTip(res.data.ErrorMsg);
							   }else{
								   // Detail_length:0,//商品明细总行数
								   // Detail_sum:0,//商品明细总数量
								   // Detail_money:0,//商品明细总金额
								   console.log('这是长度')
								   console.log(res.data.ResultMsg.length)
								   that.Detail_info = res.data.ResultMsg;
								   let money = 0;
								   let sum = 0;
								   for(let i in res.data.ResultMsg){
									   // console.log('这两个是长度')
									   // console.log(i)
									   // console.log(res.data.ResultMsg[i])
									   money += parseFloat(res.data.ResultMsg[i]['inPrice']*res.data.ResultMsg[i]['Qty'])//总金额
									   sum += parseFloat(res.data.ResultMsg[i]['Qty'])//总数量
								   }
								   that.Detail_length = res.data.ResultMsg.length;
								   that.Detail_sum = sum.toFixed(2);
								   that.Detail_money = money.toFixed(2);
								   // that.Detail_code = that.tableList[e]['BillNo']
								   // price.toFixed(2);
								   console.log('这是总金额')
								   console.log(money.toFixed(2))
								   console.log('这是总数量')
								   console.log(sum.toFixed(2))
							   }
						  }else{
							  ApiBb.showTip("服务器错误!");
						  }
					});
				console.log(e)
			},
		
			// 日期截取
			timesubstr:function(e){
				if(e=="" || typeof e=="undefined"){
					return "";
				}
				return e.substring(0,10)
			},
			//保留两位小数
			toFix:function(evt){
							 if(evt == ""|| evt==undefined){
								 return evt
							 }
							 evt = parseFloat(evt);
							 return evt.toFixed(2)//此处2为保留两位小数
			},
			//是否展开
			unfolds:function(e){
				if(this.unfold == e){
					this.unfold = -1
				}else{
					this.unfold = e
				}
			},
			//返回上一页
			back(){
				uni.navigateBack({
					delta:1
				})
			},
			//切换风格
			Switchstyles:function(){
				this.Switchstyle = this.Switchstyle == 1?2:1
			},
		}
	}
</script>

<style>
	@import url("selectdetail.css");
/* page {
		background-color: #EEEEEE;
		padding-bottom: 0upx;
		height: 100%;
	} */
</style>
